# SPDX-License-Identifier: GPL-2.0-only
# Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.

# Compile liblinux.a by -fPIC for dynamic link usage
KBUILD_CFLAGS_KERNEL += -fPIC
KBUILD_CFLAGS += -nostdlib

# Don't generate unused tracepoints for decreasing image size
ifneq ($(CONFIG_TRACING),y)
KBUILD_CFLAGS += -DNOTRACE
endif

# generate asm-generic for liblinux
PHONY += liblinux-asm-generic
asm-generic: liblinux-asm-generic
liblinux-asm-generic:
	$(Q)$(MAKE) SRCARCH=um $(asm-generic)=arch/liblinux/include/generated/asm \
	generic=include/asm-generic

# Prepend alternative header if selected
ifdef CONFIG_ALTERNATIVE_HEADER
LINUXINCLUDE := -I$(objtree)/include/alternative $(LINUXINCLUDE)
endif

# Prepend to override include search path
LINUXINCLUDE := -I$(srctree)/arch/liblinux/include \
		-I$(objtree)/arch/liblinux/include/generated \
		$(LINUXINCLUDE)

ifeq ($(CONFIG_AEABI),y)
CFLAGS_ABI := $(filter-out $(CFLAGS_ABI), -mabi=aapcs-linux)
endif

# Filter out the --be8 option to avoid reuse for dynamic link
ifeq ($(CONFIG_CPU_ENDIAN_BE8),y)
LDFLAGS_vmlinux := $(filter-out --be8, $(LDFLAGS_vmlinux))
endif
# Filter out the -shared option because we need -Ur
LDFLAGS_vmlinux := $(filter-out -shared, $(LDFLAGS_vmlinux))

# do partial link to generate relocatable output
ifneq ($(LLVM),)
LDFLAGS_vmlinux += -r
else
LDFLAGS_vmlinux += -Ur
endif

# rebuild vmlinux if override rules changed
vmlinux: $(srctree)/arch/liblinux/Makefile.override

LIBLINUX_EXTRA_FILTER_OBJS ?=
export __LIBLINUX_EXTRA_FILTER_OBJS := $(LIBLINUX_EXTRA_FILTER_OBJS)
ifeq ($(CONFIG_LIBLINUX_NET_STACK),y)
__LIBLINUX_EXTRA_FILTER_OBJS += gen_liblinux_netstack_objs.txt
endif

core-y += arch/liblinux/
